package com.atguigui.leetcode1;

/**
 * 2319.判断矩阵是否是一个 X 矩阵
 * Project: leetcode
 * Package: com.atguigui.leetcode1
 * Version: 1.0
 * <p>
 * Created by WJX on 2023/1/31 8:37
 */
public class P2319CheckIfMatrixIsXMatrix {

    public static void main(String[] args) {
        Solution solution = new P2319CheckIfMatrixIsXMatrix().new Solution();
        // TO TEST
    }

    class Solution {
        public boolean checkXMatrix(int[][] grid) {

            int m = grid[0].length;
            int n = grid.length;

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    //i=j 或者 i+j+1=n 则说明该点在矩阵 grid\textit{grid}grid 的对角线上，否则不在矩阵对角线上
                    //若在对角线上则需要满足 grid[i][j]≠0  否则需要满足 grid[i][j]=0

                    //对角线
                    if (i == j || (i + j) == (n - 1)) {
                        if (grid[i][j] == 0) {
                            return false;
                        }
                    } else if (grid[i][j] != 0) { //非对角线
                        return false;
                    }
                }
            }
            return true;
        }
    }
}
